package com.czr.controller.archives;

import com.czr.service.archives.ArchivesService;
import com.czr.vo.ArticleWithYearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * Author: czr czr
 * Version: 1.0
 * Create Date Time: 2021/11/28 11:13.
 * Update Date Time:
 *
 * @see
 */
@Controller
public class archivesController {

    @Autowired
    private ArchivesService archivesService;

    /**
     * 查询归档排序分页
     *
     * @return List<ArticleWithYearVo>
     */
    @GetMapping("/archives/load")
    @ResponseBody
    public List<ArticleWithYearVo> archivesBlogs() {
        return archivesService.queryBlogYearGroup();
    }

    @GetMapping("/archives/loadmore")
    @ResponseBody
    public List<Map<String, Object>> loadMore(Integer year,
                                              @RequestParam(defaultValue = "1") Integer pageNo,
                                              @RequestParam(defaultValue = "6") Integer pageSize) {
        return archivesService.queryBlogPages(year, pageNo, pageSize);
    }

    @GetMapping("/archives/year")
    @ResponseBody
    public List<HashMap<String, Object>> findBlogYearGroup() {
        return archivesService.findBlogYearGroup();
    }

    @GetMapping("/acv")
    public String index() {
        return "archives/index";
    }

    @GetMapping("/archives/load2")
    @ResponseBody
    public List<ArticleWithYearVo> archivesBlogs2() {
        return archivesService.getAllArchives2();
    }

}
